#! /usr/bin/env python
# coding=utf-8
# 将我这里的miRNA的 clus文件转化为 tsv格式

import argparse
import sys
from argparse import RawTextHelpFormatter




parser = argparse.ArgumentParser(
    description='''
    将clus转化为 csv文件

    用法:
    clus2csv.py -c result.clus -o miRNA_gene.csv


    ''',formatter_class=RawTextHelpFormatter)


parser.add_argument('-c',
                help='必须给定，clus 文件')


parser.add_argument('-o',
                help='输出的csv文件')


args = parser.parse_args()

if not args.c or not args.o:
    parser.print_help()
    sys.exit()




infile_clus = args.c
outfile = args.o


# infile_clus = 'result.clus'
# outfile = r'miRNA_gene.csv'


outfile = open(outfile,'w')

with open(infile_clus) as fila:
	outfile.write('gene_id,gene_acc,gene_name,type,gene_symbol,gene_description,swissprot,seq_name,direction,start,end\n')
	for i in fila:
		k = i.strip().split('\t')
		if len(k)>5:
			gene_symbol = k[2]
			gene_name = k[1]
			outfile.write(','+gene_name+','+gene_name+','+'miRNA'+','+gene_symbol+','+','+','+k[6]+','+k[7]+','+k[8]+','+k[9]+'\n')
